package razie.draw.swing;

import razie.base._
import razie.draw._
import razie.draw.widgets._
import com.razie.pub.resources._

import scala.swing._

// for DrawString, DrawText and DrawToString
class ScriptPadRenderer extends Renderer[ScriptPad] {
   
  override def render(f:ScriptPad , t:Technology , out:DrawStream ) :AnyRef = {

    val ed1 = new TextArea(f.icontents, f.rows, f.cols)
    val ed2 = new TextArea("result here", 3, 50)
     
    val b = razie.Draw.button(razie.AI("vvv Run script vvv")) { 
      val s = ed1.text
      val ati = f.run()
      ati.set ("language", "scala")
      ati.set ("script", s)
      val r = ati.act(null)
      ed2.text = if (r==null) "<null>" else r.toString
      }
            
    new BoxPanel (Orientation.Vertical) {
      contents += Init.swingify (razie.Draw.label("Scripting:"),t,out)
      contents += ed1
      contents += Init.swingify (b, t,out)
      contents += ed2
    }
  }
}
